```js
// ======Question 1======

setTimeout(function () {
  console.log(8)
}, 0)
async function async1() {
  console.log(1)
  const data = await async2()
  console.log(6)
  return data
}
async function async2() {
  return new Promise((resolve) => {
    console.log(2)
    resolve(11)
  })
    .then((data) => {
      console.log(4)
      return data
    })
    .then((data) => {
      console.log(9)
      return data
    })
    .then((data) => {
      console.log(10)
      return data
    })
}
async1().then((data) => {
  console.log(7)
  console.log(data)
})
new Promise(function (resolve) {
  console.log(3)
  resolve()
}).then(function () {
  console.log(5)
})

// ======Question 2======

setTimeout(function () {
  console.log(8)
}, 0)
async function async1() {
  console.log(1)
  const data = await async2()
  console.log(6)
  return data
}
async function async2() {
  return new Promise((resolve) => {
    console.log(2)
    resolve(11)
  }).then((data) => {
    console.log(4)
    return data
  })
}
async1().then((data) => {
  console.log(7)
  console.log(data)
})
new Promise(function (resolve) {
  console.log(3)
  resolve()
}).then(function () {
  console.log(5)
})

// ======Question 3======

setTimeout(function () {
  console.log(8)
}, 0)
async function async1() {
  console.log(1)
  const data = await async2()
  console.log(6)
  return data
}
async function async2() {
  return new Promise((resolve) => {
    console.log(2)
    resolve(11)
  })
}
async1().then((data) => {
  console.log(7)
  console.log(data)
})
new Promise(function (resolve) {
  console.log(3)
  resolve()
}).then(function () {
  console.log(5)
})

// ======Question 4======

async function async1() {
  console.log('1')
  await async2()
  console.log('2')
}
async function async2() {
  console.log('3')
}

console.log('4')

setTimeout(function () {
  console.log('5')
}, 0)

async1()

new Promise(function (resolve) {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})
console.log('8')

// ======Question 5======

async function async1() {
  console.log('1')
  await async2()
  console.log('2')
}
async function async2() {
  /* return new Promise(function (resolve) { */
  new Promise(function (resolve) {
    console.log('3')
    resolve()
  }).then(function () {
    console.log('4')
  })
}
console.log('5')

setTimeout(function () {
  console.log('6')
}, 0)
async1()

new Promise(function (resolve) {
  console.log('7')
  resolve()
}).then(function () {
  console.log('8')
})

console.log('9')

// ======Question 6======

async function async1() {
  console.log('1')
  await async2()
  setTimeout(function () {
    console.log('2')
  }, 0)
}
async function async2() {
  setTimeout(function () {
    console.log('3')
  }, 0)
}
console.log('4')

setTimeout(function () {
  console.log('5')
}, 0)
async1()

new Promise(function (resolve) {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})
console.log('8')

// ======Question 7======

async function a1() {
  console.log('1')
  await a2()
  console.log('2')
}
async function a2() {
  console.log('3')
}

console.log('4')

setTimeout(() => {
  console.log('5')
}, 0)

Promise.resolve().then(() => {
  console.log('6')
})

a1()

let promise2 = new Promise((resolve) => {
  resolve('7')
  console.log('8')
})

promise2.then((res) => {
  console.log(res)
  Promise.resolve().then(() => {
    console.log('9')
  })
})
console.log('10')

// ======Question 8======

const promise = new Promise((resolve, reject) => {
  resolve('1')
  reject('2')
  resolve('3')
})

promise
  .then((res) => {
    console.log('4:', res)
  })
  .catch((err) => {
    console.log('5:', err)
  })

// ======Question 9======

const promise = new Promise((resolve, reject) => {
  console.log(1)
  resolve()
  console.log(2)
})

promise.then(() => {
  console.log(3)
})

console.log(4)

// ======Question 10======

const promise = () =>
  new Promise((resolve, reject) => {
    console.log(3)
    let p = new Promise((resolve, reject) => {
      console.log(7)
      setTimeout(() => {
        console.log(5)
        resolve(6)
      }, 0)
      resolve(1)
    })
    resolve(2)
    p.then((arg) => {
      console.log(arg)
    })
  })

promise().then((arg) => {
  console.log(arg)
})
console.log(4)

// ======Question 11======

console.log('1')

setTimeout(function () {
  console.log('2')
  new Promise(function (resolve) {
    resolve()
  }).then(function () {
    new Promise(function (resolve) {
      resolve()
    }).then(function () {
      console.log('3')
    })
    console.log('4')
  })
})

new Promise(function (resolve) {
  console.log('5')
  resolve()
}).then(function () {
  console.log('6')
})

setTimeout(function () {
  console.log('7')
})

console.log('11')

queueMicrotask(() => {
  console.log('8')
})

new Promise(function (resolve) {
  resolve()
}).then(function () {
  console.log('9')
})

console.log('10')

// ======Question 12======

async function async1() {
  console.log('1')
  await async2()

  console.log('2')
}

async function async2() {
  console.log('3')
}

console.log('4')

setTimeout(function () {
  console.log('5')
}, 0)

async1()

new Promise(function (resolve) {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})

console.log('8')

// ======Question 13======

console.log('1')
async function async1() {
  await async2()
  console.log('2')
}
async function async2() {
  console.log('3')
}
async1()
setTimeout(function () {
  console.log('4')
}, 0)
new Promise((resolve) => {
  console.log('5')
  resolve()
})
  .then(function () {
    console.log('6')
  })
  .then(function () {
    console.log('7')
  })
console.log('8')

// ======Question 14======

let a = 1
console.log(a)

setTimeout(() => {
  console.log(a)
}, 1000)
let b = 2
for (let i = 0; i < 10000; i++) {
  console.log(b)
}

// ======Question 15======

console.log('1')
setTimeout(() => {
  console.log('2')
  setTimeout(() => {
    console.log('3')
  })
  console.log('4')
}, 1000)
new Promise((resolve, reject) => {
  console.log('5')
  resolve()
})
  .then(() => {
    console.log('6')
  })
  .then(() => {
    console.log('7')
  })
  .then(() => {
    console.log('8')
  })

// ======Question 16======

function a() {
  setTimeout(() => {
    console.log('1')
  }, 1000)
}
function b() {
  setTimeout(() => {
    console.log('2')
  }, 500)
}
a()
b()

// ======Question 17======

console.log('1')
async function async1() {
  await async2()
  console.log('2')
}
async function async2() {
  console.log('3')
}
async1()
setTimeout(function () {
  console.log('4')
}, 0)
new Promise((resolve) => {
  console.log('5')
  resolve()
})
  .then(function () {
    console.log('6')
  })
  .then(function () {
    console.log('7')
  })
console.log('8')

// ======Question 18======

console.log(1)
setTimeout(() => console.log(2))
new Promise((resolve, reject) => {
  Promise.resolve(3).then((result) => {
    console.log(result)
  })
  resolve()
  console.log(4)
}).then(
  (result) => {
    console.log(result)
  },
  (error) => {
    console.log(error)
  }
)
console.log(5)

// ======Question 19======

console.log(1)
new Promise((resolve, reject) => {
  console.log(2)
  resolve()
}).then((res) => {
  console.log(3)
})
console.log(4)

// ======Question 20======

setTimeout(function () {
  console.log(1)
}, 0)

new Promise(function (resolve, reject) {
  console.log(2)
  resolve()
})
  .then(function () {
    console.log(3)
  })
  .then(function () {
    console.log(4)
  })

console.log(6)

// ======Question 21======

setTimeout(function () {
  console.log(1)
}, 0)

new Promise(function (resolve, reject) {
  console.log(2)
  for (var i = 0; i < 10000; i++) {
    if (i === 10) {
      console.log(10)
    }
    i == 9999 && resolve()
  }
  console.log(3)
}).then(function () {
  console.log(4)
})
console.log(5)

// ======Question 22======

console.log('1')
setTimeout(() => {
  console.log('2')
  Promise.resolve().then(() => {
    console.log('3')
  })
}, 0)

new Promise(function (resolve, reject) {
  console.log('4')
  setTimeout(function () {
    console.log('5')
    resolve('6')
  }, 0)
}).then((res) => {
  console.log('7')
  setTimeout(() => {
    console.log(res)
  }, 0)
})

// ======Question 23======

async function async1() {
  console.log('1')
  await async2()
  console.log('2')
}
async function async2() {
  console.log('3')
}
console.log('4')
setTimeout(function () {
  console.log('5')
}, 0)
async1()
new Promise((resolve) => {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})
console.log('8')

// ======Question 24======

async function async1() {
  console.log('1')
  await async2()
  console.log('2')
}
async function async2() {
  new Promise(function (resolve) {
    console.log('3')
    resolve()
  }).then(function () {
    console.log('4')
  })
}
console.log('5')
setTimeout(function () {
  console.log('6')
}, 0)
async1()
new Promise(function (resolve) {
  console.log('7')
  resolve()
}).then(function () {
  console.log('8')
})
console.log('9')

// ======Question 25======

async function async1() {
  console.log('1')
  await async2()
  setTimeout(function () {
    console.log('2')
  }, 0)
}
async function async2() {
  setTimeout(function () {
    console.log('3')
  }, 0)
}
console.log('4')
setTimeout(function () {
  console.log('5')
}, 0)
async1()
new Promise(function (resolve) {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})
console.log('8')

```
### 演示

```js
// 渲染主线程在执行任务时 有可能还会产生其他任务

// ======Question 4======

/* async function async1() {
  console.log('1')
  await async2()
  console.log('2')
}
async function async2() {
  console.log('3')
}

console.log('4')

setTimeout(function () {
  console.log('5')
}, 0)

async1()

new Promise(function (resolve) {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})
console.log('8') */

// 4 1 3 6 8 2 7 5

/* async function async1() {
  console.log('1')
  await async2()
  console.log('2')
}
async function async2() {
  console.log('3')
}

console.log('4')

setTimeout(function () {
  console.log('5')
}, 0)

async1()
  .then((data) => {
    console.log('9')
    console.log(data)
  })
  .then((data) => {
    console.log('10')
    console.log(data)
  })
  .then((data) => {
    console.log('11')
    console.log(data)
  })

new Promise(function (resolve) {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})
console.log('8') */

// 4 1 3 6 8 2 7 9 undefined 10 undefined 11 undefined 5

// ======Question 5======

/* async function async1() {
  console.log('1')
  await async2() // 返回值不是 Promise 实例对象
  console.log('2') // 会被立即包装成微任务(() => console.log('2')) 等待执行
}
async function async2() {
  new Promise(function (resolve) {
    console.log('3')
    resolve()
  }).then(function () {
    console.log('4')
  })
}
console.log('5')

setTimeout(function () {
  console.log('6')
}, 0)
async1()

new Promise(function (resolve) {
  console.log('7')
  resolve()
}).then(function () {
  console.log('8')
})

console.log('9') */

// 5 1 3 7 9 4 2 8 6

/* async function async1() {
  console.log('1')
  await async2() // 返回值是 Promise 实例对象
  console.log('2') // 等await执行完微队列中任务再去包装成微任务函数(() => console.log('2'))等待去执行
}
async function async2() {
  return new Promise(function (resolve) {
    console.log('3')
    resolve()
  }).then(function () {
    console.log('4')
  })
}
console.log('5')

setTimeout(function () {
  console.log('6')
}, 0)
async1()

new Promise(function (resolve) {
  console.log('7')
  resolve()
}).then(function () {
  console.log('8')
})

console.log('9') */

// 5 1 3 7 9 4 8 2 6

/* async function async1() {
  console.log('1')
  async2() // 没有 await  执行完后 直接往下执行
  console.log('2') // 不用包装成微队列中任务函数
}
async function async2() {
  return new Promise(function (resolve) {
    console.log('3')
    resolve()
  }).then(function () {
    console.log('4')
  })
}
console.log('5')

setTimeout(function () {
  console.log('6')
}, 0)
async1()

new Promise(function (resolve) {
  console.log('7')
  resolve()
}).then(function () {
  console.log('8')
})

console.log('9') */

// 5 1 3 2 7 9 4 8 6

// ======Question 6======

/* async function async1() {
  console.log('1')
  await async2() // 返回值不是 Promise 实例对象
  console.log('2') // 会被立即包装成微任务(() => console.log('2')) 等待执行
}
async function async2() {
  setTimeout(function () {
    console.log('3')
  }, 0)
}
console.log('4')

setTimeout(function () {
  console.log('5')
}, 0)
async1()

new Promise(function (resolve) {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})
console.log('8') */

// 4 1 6 8 2 7 5 3

/* async function async1() {
  console.log('1')
  await async2() // 返回值不是 Promise 实例对象
  setTimeout(function () {
    // 会被立即包装成微任务(() => setTimeout(f2, 0)) 等待执行
    console.log('2')
  }, 0)
}
async function async2() {
  setTimeout(function () {
    console.log('3')
  }, 0)
}
console.log('4')

setTimeout(function () {
  console.log('5')
}, 0)
async1()

new Promise(function (resolve) {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})
console.log('8') */

// 4 1 6 8 7 5 3 2

// ======Question 7======

/* async function a1() {
  console.log('1')
  await a2() // 返回值不是 Promise 实例对象
  console.log('2')  // 会被立即包装成微任务(() => console.log('2')) 等待执行
}
async function a2() {
  console.log('3')
}

console.log('4')

setTimeout(() => {
  console.log('5')
}, 0)

Promise.resolve().then(() => {
  console.log('6')
})

a1()

let promise2 = new Promise((resolve) => {
  resolve('7')
  console.log('8')
})

promise2.then((res) => {
  console.log(res)
  Promise.resolve().then(() => {
    console.log('9')
  })
})
console.log('10') */
// 4 1 3 8 10 6 2 7 9 5

// ======Question 24======

/* async function async1() {
  console.log('1') // 返回值不是 Promise 实例对象
  await async2()
  console.log('2') // 会被立即包装成微任务(() => console.log('2')) 等待执行
}
async function async2() {
  new Promise(function (resolve) {
    console.log('3')
    resolve()
  }).then(function () {
    console.log('4')
  })
}
console.log('5')
setTimeout(function () {
  console.log('6')
}, 0)
async1()
new Promise(function (resolve) {
  console.log('7')
  resolve()
}).then(function () {
  console.log('8')
})
console.log('9') */
// 5 1 3 7 9 4 2 8 6

// ======Question 1======

/* setTimeout(function () {
  console.log(8)
}, 0)
async function async1() {
  console.log(1)
  const data = await async2() // 返回值是 Promise 实例对象 一直等待resolve()产生的微任务执行完才返回
  console.log(6) // 等await执行完微队列中任务再去包装成微任务函数(() => console.log(6))等待去执行
  return data
}
async function async2() {
  return new Promise((resolve) => {
    console.log(2)
    resolve(11)
  })
    .then((data) => {
      console.log(4)
      return data
    })
    .then((data) => {
      console.log(9)
      return data
    })
    .then((data) => {
      console.log(10)
      return data
    })
}
async1().then((data) => {
  console.log(7)
  console.log(data)
})
new Promise(function (resolve) {
  console.log(3)
  resolve()
}).then(function () {
  console.log(5)
}) */
// 1 2 3 4 5 9 10 6 7 11 8
/* 
setTimeout(function () {
  console.log(8)
}, 0)
async function async1() {
  console.log(1)
  const data2 = await async2() // 返回值是 Promise 实例对象 一直等待resolve()产生的微任务执行完才返回
  console.log(6) // 等await执行完微队列中任务再去包装成微任务函数(() => console.log(6))等待去执行
  const data3 = await async3()
  console.log(22)
  const data4 = await async4()
  console.log(23)
  return Promise.resolve([data2, data3, data4])
}
async function async2() {
  return new Promise((resolve) => {
    console.log(2)
    resolve(11)
  }).then((data) => {
    console.log(4)
    return data
  })
}
async function async3() {
  return new Promise((resolve) => {
    console.log(12)
    resolve(13)
  }).then((data) => {
    console.log(14)
    return data
  })
}

async function async4() {
  new Promise((resolve) => {
    console.log(17)
    resolve(18)
  }).then((data) => {
    console.log(19)
    return data
  })
}
async1().then((data) => {
  console.log(7)
  console.log(data)
})

new Promise(function (resolve) {
  console.log(3)
  resolve()
}).then(function () {
  console.log(5)
}) */

/* setTimeout(function () {
  console.log(8)
}, 0)
async function async1() {
  console.log(1)
  const data = await async2() // 返回值不是 Promise 实例对象
  console.log(6) // 会被立即包装成微任务(() => console.log(6)) 等待执行 这里不会等待await内部的微任务全部执行完 ，而是执行完(() => console.log(6))后继续往下执行
  return data
}
async function async2() {
  new Promise((resolve) => {
    console.log(2)
    resolve(11)
  })
    .then((data) => {
      console.log(4)
      return data
    })
    .then((data) => {
      console.log(9)
      return data
    })
    .then((data) => {
      console.log(10)
      return data
    })
}
// async1()只有等内部代码(内部直接微任务)真正执行完才算结束才算得到返回值
async1().then((data) => {
  console.log(7)
  console.log(data)
})
new Promise(function (resolve) {
  console.log(3)
  resolve()
}).then(function () {
  console.log(5)
}) */

// 1 2 3 4 6 5 9 7 undefined 10 8

// ======Question 2======

/* setTimeout(function () {
  console.log(8)
}, 0)
async function async1() {
  console.log(1)
  const data = await async2() // 返回值是 Promise 实例对象
  console.log(6) // 等await执行完微队列中任务再去包装成微任务函数(() => console.log(6))等待去执行
  return data
}
async function async2() {
  return new Promise((resolve) => {
    console.log(2)
    resolve(11)
  }).then((data) => {
    console.log(4)
    return data
  })
}
async1().then((data) => {
  console.log(7)
  console.log(data)
})
new Promise(function (resolve) {
  console.log(3)
  resolve()
}).then(function () {
  console.log(5)
}) */

// 1 2 3 4 5 6 7 11 8

/* setTimeout(function () {
  console.log(8)
}, 0)
async function async1() {
  console.log(1)
  const data = await async2() // 返回值不是 Promise 实例对象
  console.log(6) // 会被立即包装成微任务(() => console.log(6)) 等待执行
  return data
}
async function async2() {
  new Promise((resolve) => {
    console.log(2)
    resolve(11)
  }).then((data) => {
    console.log(4)
    return data
  })
}
// async1() 内的任务全部执行完 才会走后面.then 产生微任务
async1().then((data) => {
  console.log(7)
  console.log(data)
})
new Promise(function (resolve) {
  console.log(3)
  resolve()
}).then(function () {
  console.log(5)
}) */
// 1 2 3 4 6 5 7 undefined 8

// ======Question 3======

/* setTimeout(function () {
  console.log(8)
}, 0)
async function async1() {
  console.log(1)
  const data = await async2()
  console.log(6)
  return data
}
async function async2() {
  return new Promise((resolve) => {
    console.log(2)
    resolve(11)
  })
}
async1().then((data) => {
  console.log(7)
  console.log(data)
})
new Promise(function (resolve) {
  console.log(3)
  resolve()
}).then(function () {
  console.log(5)
}) */
// 1 2 3 5 6 7 11 8

// ======Question 22======

/* console.log('1')
setTimeout(() => {
  console.log('2')
  Promise.resolve().then(() => {
    console.log('3')
  })
}, 0)

new Promise(function (resolve, reject) {
  console.log('4')
  setTimeout(function () {
    console.log('5')
    resolve('6') // 产生微队列中的任务
  }, 0)
}).then((res) => {
  console.log('7')
  setTimeout(() => {
    console.log(res)
  }, 0)
}) */
// 1 4 2 3 5 7 6

// ======Question 21======

/* setTimeout(function () {
  console.log(1)
}, 0)

new Promise(function (resolve, reject) {
  console.log(2)
  for (var i = 0; i < 10000; i++) {
    if (i === 10) {
      console.log(10)
    }
    i == 9999 && resolve()
  }
  console.log(3)
}).then(function () {
  console.log(4)
})
console.log(5) */
// 2 10 3 5 4 1

// ======Question 20======

/* setTimeout(function () {
  console.log(1)
}, 0)

new Promise(function (resolve, reject) {
  console.log(2)
  resolve()
})
  .then(function () {
    console.log(3)
  })
  .then(function () {
    console.log(4)
  })

console.log(6) */
// 2 6 3 4 1

// ======Question 19======

/* console.log(1)
new Promise((resolve, reject) => {
  console.log(2)
  resolve()
}).then((res) => {
  console.log(3)
})
console.log(4) */
// 1 2 4 3

// ======Question 18======

/* console.log(1)
setTimeout(() => console.log(2))
new Promise((resolve, reject) => {
  Promise.resolve(3).then((result) => {
    console.log(result)
  })
  resolve()
  console.log(4)
}).then(
  (result) => {
    console.log(result)
  },
  (error) => {
    console.log(error)
  }
)
console.log(5) */

// 1 4 5 3 undefined 2

// ======Question 17======

/* console.log('1')
async function async1() {
  await async2()
  console.log('2')
}
async function async2() {
  console.log('3')
}
async1()
setTimeout(function () {
  console.log('4')
}, 0)
new Promise((resolve) => {
  console.log('5')
  resolve()
})
  .then(function () {
    console.log('6')
  })
  .then(function () {
    console.log('7')
  })
console.log('8') */
// 1 3 5 8 2 6 7 4

// ======Question 16======

/* function a() {
  setTimeout(() => {
    console.log('1')
  }, 1000)
}
function b() {
  setTimeout(() => {
    console.log('2')
  }, 500)
}
a()
b() */

// 2 1

/* Promise.resolve()
  .then(() => {
    return new Error(1)
  })
  .then((data) => {
    console.log(2, data)
  })
  .catch((err) => {
    console.log(3, err)
  })
 */

/* Promise.resolve()
  .then(() => {})
  .then((data) => {
    console.log(2, data)
  })
  .catch((err) => {
    console.log(3, err)
  }) */

/* Promise.resolve()
  .then(() => {
    throw new Error(1)
  })
  .then((data) => {
    console.log(2, data)
  })
  .catch((err) => {
    console.log(3, err)
  }) */

/* new Promise((resolve, reject) => {})
  .then(() => {
    console.log(1)
  })
  .then((data) => {
    console.log(2, data)
  })
  .catch((err) => {
    console.log(3, err)
  }) */

// ======Question 15======

/* console.log('1')
setTimeout(() => {
  console.log('2')
  setTimeout(() => {
    console.log('3')
  })
  console.log('4')
}, 1000)
new Promise((resolve, reject) => {
  console.log('5')
  resolve()
})
  .then(() => {
    console.log('6')
  })
  .then(() => {
    console.log('7')
  })
  .then(() => {
    console.log('8')
  }) */

// 1 5 6 7 8 2 4 3

// ======Question 14======

/* let a = 1
console.log(a)

setTimeout(() => {
  console.log(a)
}, 1000)
let b = 2
for (let i = 0; i < 10; i++) {
  console.log(b)
} */

// ======Question 13======

/* console.log('1')
async function async1() {
  await async2()
  console.log('2')
}
async function async2() {
  console.log('3')
}
async1()
setTimeout(function () {
  console.log('4')
}, 0)
new Promise((resolve) => {
  console.log('5')
  resolve()
})
  .then(function () {
    console.log('6')
  })
  .then(function () {
    console.log('7')
  })
console.log('8') */
// 1 3 5 8 2 6 7 4

// ======Question 12======

/* async function async1() {
  console.log('1')
  await async2()

  console.log('2')
}

async function async2() {
  console.log('3')
}

console.log('4')

setTimeout(function () {
  console.log('5')
}, 0)

async1()

new Promise(function (resolve) {
  console.log('6')
  resolve()
}).then(function () {
  console.log('7')
})

console.log('8') */
// 4 1 3 6 8 2 7 5

// ======Question 11======
/* 
console.log('1')
setTimeout(function () {
  console.log('2')
  new Promise(function (resolve) {
    resolve()
  }).then(function () {
    new Promise(function (resolve) {
      resolve()
    }).then(function () {
      console.log('3')
    })
    console.log('4')
  })
})

new Promise(function (resolve) {
  console.log('5')
  resolve()
}).then(function () {
  console.log('6')
})

setTimeout(function () {
  console.log('7')
})

console.log('11')

queueMicrotask(() => {
  console.log('8')
})

new Promise(function (resolve) {
  resolve()
}).then(function () {
  console.log('9')
})

console.log('10') */
// 1 5 11 10 6 8 9 2 4 3 7

// ======Question 10======

/* const promise = () =>
  new Promise((resolve, reject) => {
    console.log(3)
    let p = new Promise((resolve, reject) => {
      console.log(7)
      setTimeout(() => {
        console.log(5)
        resolve(6) // resolve 只能被调用一次 所以这里无效
      }, 0)
      resolve(1)
    })
    resolve(2)
    p.then((arg) => {
      console.log(arg)
    })
  })

promise().then((arg) => {
  console.log(arg)
})
console.log(4) */
// 3 7 4 1 2 5

/* const promise = () =>
  new Promise((resolve, reject) => {
    console.log(3)
    let p = new Promise((resolve, reject) => {
      console.log(7)
      setTimeout(() => {
        console.log(5)
        resolve(6)
      }, 0)
      resolve(1)
    })
    resolve(2)
    p.then((arg) => {
      console.log(arg)
    }).then((arg) => {
      console.log(arg)
    })
  })

promise().then((arg) => {
  console.log(arg)
})
console.log(4) */
// 3 7 4 1 2 undefined 5

// ======Question 9======

/* const promise = new Promise((resolve, reject) => {
  console.log(1)
  resolve()
  console.log(2)
})

promise.then(() => {
  console.log(3)
})

console.log(4) */
// 1 2 4 3

// ======Question 8======

/* const promise = new Promise((resolve, reject) => {
  resolve('1')
  reject('2') // resolve, reject 只会执行其中之一
  resolve('3') // 只会执行第一次的执行
})
promise
  .then((res) => {
    console.log('4:', res)
  })
  .catch((err) => {
    console.log('5:', err)
  })
 */
```

